package app.blog.entity;

import slap.berkeleydb.BDB;
import app.blog.Blog;

import com.sleepycat.persist.PrimaryIndex;
import com.sleepycat.persist.SecondaryIndex;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
import com.sleepycat.persist.model.Relationship;
import com.sleepycat.persist.model.SecondaryKey;


@Entity
public class PostJoinCategory {
	
	protected static PrimaryIndex<Long, PostJoinCategory> primaryIndex = 
		BDB.instanse(Blog.bdbName).getEntityStore().getPrimaryIndex(Long.class, PostJoinCategory.class);
	
	protected static SecondaryIndex<Integer, Long, PostJoinCategory> indexOnPostId = 
		BDB.instanse(Blog.bdbName).getEntityStore().getSecondaryIndex(primaryIndex, Integer.class, "post_id");
	
	protected static SecondaryIndex<Integer, Long, PostJoinCategory> indexOnCategoryID = 
		BDB.instanse(Blog.bdbName).getEntityStore().getSecondaryIndex(primaryIndex, Integer.class, "category_id");
	
	public static void persist(PostJoinCategory jion){
		primaryIndex.put(jion);
	}
	
	private PostJoinCategory(){
	}
	
	public PostJoinCategory(Integer post_id, Integer category_id) {
		this.post_id = post_id;
		this.category_id = category_id;
	}

	@PrimaryKey(sequence = "pjc-id")
    Long id;
	
	@SecondaryKey(relate = Relationship.MANY_TO_ONE, relatedEntity = Article.class)
    public Integer post_id;
	
	@SecondaryKey(relate = Relationship.MANY_TO_ONE, relatedEntity = Category.class)
    public Integer category_id;
}
